<script lang="ts" setup>

import {Resource, resourceMap} from "../js/Resource";
import {data} from "../js/Data.ts";
import {Util} from "../js/Util.ts";
import {PlanetResource} from "../js/PlanetResource.ts";
import {itemMap} from "../js/Item.ts";

let planetResourceData = data.planetResourceData.filter((r) => r.planetId == data.current.planet.id)

let hand = (s: PlanetResource) => {
  // let itemKey: string = resourceToItem(s.rt)
  // let item = globalConfig.inventory.get(itemKey)
  // if (s.ri) {
  //   if (!item) {
  //     item = Object.assign({num: 1}, itemInfo.get(itemKey))
  //     globalConfig.inventory.set(itemKey, item)
  //   } else if (item.ic < item.im) {
  //     item.ic += 1
  //   }
  // } else {
  //   if (!item) {
  //     item = Object.assign({num: 1}, itemInfo.get(itemKey))
  //     globalConfig.inventory.set(itemKey, item)
  //     s.rn -= 1
  //   } else if (item.ic < item.im) {
  //     item.ic += 1
  //     s.rn -= 1
  //   }
  //   if (s.rn == 0) {
  //     rl.splice(rl.indexOf(s), 1)
  //   }
  // }
}

let addMachineForOil = (r: Resource) => {

}

let addMachineForGas = (r: Resource) => {

}

let addMineMachine = (r: Resource) => {
  // let machine = globalConfig.inventory.get(Ik.采矿机)
  // if (machine == undefined) {
  //   return
  // }
  // if (machine.ic == 0) {
  //   return
  // }
  // machine.ic -= 1
  // r.rl += 1
  // r.re += getMachineEnergy(machine.ina)
  // globalConfig.current.planet.pau += machine.ia
}

let addHugeMineMachine = (r: Resource) => {

}
</script>

<template>
  <n-table :bordered="false" style="margin-top: 10px">
    <thead>
    <tr>
      <th></th>
      <th>类型</th>
      <th>资源数</th>
      <th>恢复速度</th>
      <th>操作</th>
    </tr>
    </thead>
    <tbody>
    <tr v-for="pr in planetResourceData">
      <td>
        <n-image-group>
          <n-space>
            <n-image
                :src=Util.srcHandler(resourceMap.get(pr.itemId))
                width="32"
            />
          </n-space>
        </n-image-group>
      </td>
      <td>{{ resourceMap.get(pr.itemId)?.name ?? '' }}</td>
      <td>
        <n-tag v-if="pr.remain * 10 >= pr.total" :bordered="false" type="success">
          {{ pr.remain }}
        </n-tag>
        <n-tag v-if="pr.remain * 10 < pr.total" :bordered="false" type="warning">
          {{ pr.remain }}
        </n-tag>
      </td>
      <td>{{ pr.recover }}</td>
      <td>
        <n-button-group>
          <n-button
              v-if="itemMap.get(resourceMap.get(pr.itemId)?.itemId ?? 0)?.handCollect"
              type="default"
              @click="hand(pr)"
          >
            收集
          </n-button>
          <!--          <n-button-->
          <!--              type="default"-->
          <!--              v-if="r.ri && r.rt != 'oil'"-->
          <!--              @click="addMachineForOil(r)"-->
          <!--          >-->
          <!--            增加原油萃取站-->
          <!--          </n-button>-->
          <!--          <n-button-->
          <!--              v-if="r.ri && r.rt == 'oil'"-->
          <!--              type="default"-->
          <!--              @click="addMachineForGas(r)"-->
          <!--          >-->
          <!--            增加轨道采集器-->
          <!--          </n-button>-->
          <!--          <n-button-->
          <!--              v-if="!r.ri"-->
          <!--              type="default"-->
          <!--              @click="addMineMachine(r)"-->
          <!--          >-->
          <!--            增加矿机-->
          <!--          </n-button>-->
          <!--          <n-button-->
          <!--              v-if="!r.ri"-->
          <!--              type="default"-->
          <!--              @click="addHugeMineMachine(r)"-->
          <!--          >-->
          <!--            增加大矿机-->
          <!--          </n-button>-->
        </n-button-group>
      </td>
    </tr>
    </tbody>
  </n-table>
</template>

<style scoped>

</style>